﻿using Google.Protobuf;
using Server.Framework.Message;
using Server.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Message.Response
{
    /// <summary>
    /// Author: Leil
    /// Description: 类描述
    /// CreateTime: 2020/5/13 12:31:32
    /// </summary>
    class LoginResp : ResponseBaseMessage
    {

        public LoginResp(int msgId):base(msgId)
        {

        }

        public int Code { get; set; }
        public string ErrMsg { get; set; }
        public UserDao LoginUser { get; set; }

        public override byte[] Serialize()
        {
            ResponseLogin msg = new ResponseLogin
            {
                Code = Code,
                ErrMsg = ErrMsg ?? string.Empty,
            };

            if (LoginUser != null)
            {
                User u = new User()
                {
                    Id = LoginUser.ID,
                    OrgId = LoginUser.OrgId,
                    LoginName = LoginUser.LoginName,
                    Password = LoginUser.Password,
                    Sort = LoginUser.Sort,
                };
                u.RoleIds.AddRange(LoginUser.RoleIds);
                msg.LoginUser = u;
            }

            return msg.ToByteArray();
        }
    }
}
